import { spaceid } from './config';
import check from '@feidao/web/atom/nodejs/captcha/check';
import call_service from '@feidao/web/atom/nodejs/msg/call-service';
interface Message {
	cookie: { uk: string; };
	query: { [key: string]: string };
}

export default async function atom(msg: Message, action_id: string, session_id: string) {
	const query = msg.query;
	// 解析参数
	const user_name = query.user_name;
	const captcha = query.captcha;
	// 判断验证码是否正确
	const res = await check(msg.cookie, captcha);
	// 返回值为boolean
	if (res) {
		// 验证码正确
		// 调用登录服务，返回值为示例，以实际返回值为准
		const u = await call_service<{ user: { sessionid: string } }>(action_id, session_id, spaceid, '', {});
		// 获取到用户信息
		const sessionid = u.user.sessionid;

		return { data: { user: u.user }, cookie: { sessionid } };
	} else {
		// 验证码错误
		// 返回错误信息
		return { data: { error_code: 0, err_info: '' } };
	}
}
